﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class ZLGLAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InitialDropDown();
        }

        protected void saveLinkButton_Click(object sender, EventArgs e)
        {
            ResourceService service = new ResourceService();
            Resource resource = new Resource();
            resource.ClientDescription = clientDescriptionTextBox.Text;
            resource.ProblemDescription = descriptionTextBox.Text;
            resource.SubmitDate = DateTime.Now;
            resource.SubmitPerson = ContextService.CurrentAccount.UserName;
            resource.ProductType = productTypeDropDownList.SelectedItem.Text;
            resource.ProblemType = problemTypeDropDownList.SelectedItem.Text;
            resource.Status = "未处理";

            service.AddResource(resource);
            reset();
        }

        private void reset()
        {
            clientDescriptionTextBox.Text = "";
            descriptionTextBox.Text = "";
        }

        private void InitialDropDown()
        {
            ProblemTypeService ptservice = new ProblemTypeService();
            List<ProblemType> problemTypeList = ptservice.GetAllProblemType();
            foreach (ProblemType type in problemTypeList)
            {
                problemTypeDropDownList.Items.Add(new ListItem(type.Name, type.ID.ToString()));
            }
            ProductClassService classService = new ProductClassService();
            productTypeDropDownList.DataSource = classService.GetAllClassWithSelectOneByUser(ContextService.CurrentAccount);
            productTypeDropDownList.DataTextField = "Name";
            productTypeDropDownList.DataValueField = "ID";
            productTypeDropDownList.DataBind();
        }

    }
}
